package com.heimatest;

import java.util.ArrayList;

public class test01 {
    public static void main(String[] args) {
        //1.创建集合遍历整数集合
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        //2.遍历字符
        ArrayList<Character> list1 = new ArrayList<>();
        list1.add('a');
        list1.add('a');
        list1.add('a');
        list1.add('a');

        print(list);
        printChar(list1);
    }

    private static void print(ArrayList<Integer> list) {
        System.out.print("[");
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size()-1){
                System.out.print(list.get(i));
                break;
            }
            System.out.print(list.get(i)+",");
        }
        System.out.println("]");
    }

    private static void printChar(ArrayList<Character> list) {
        System.out.print("[");
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size()-1){
                System.out.print(list.get(i));
                break;
            }
            System.out.print(list.get(i)+",");
        }
        System.out.println("]");
    }
}
